/* delete popover hooks
* 视图页table 删除操作
*  */
import { ref, nextTick } from 'vue'

export default function useDelPop() {
    // 是否显示删除浮窗 通用
    const visibleDelPop = ref(false)
    // 动态的el
    const tempRef = ref()
    /*删除需要的数据
    * @params {number} id row的id
    * @params {string} title row的数据名
    * */
    const delData = ref({
        id: undefined,
        title: ''
    })

    // 显示删除的popover
    const showDelPop = (e, row, title) => {
        const evt = e || window.e || window.event
        delData.value.id = row.id
        delData.value.title = row[title] || title
        // 通过设置false 销毁poppover, 解决闪现问题
        if (tempRef.value) visibleDelPop.value = false
        nextTick(() => {
            tempRef.value = evt.currentTarget
            visibleDelPop.value = true
        }).then()
    }
    // 取消删除，还原数据
    const cancelDelete = () => {
        delData.value.id = ''
        delData.value.title = ''
        visibleDelPop.value = false
    }
    return {
        cancelDelete,
        delData,
        visibleDelPop,
        tempRef,
        showDelPop
    }
}
